package com.iiapk.gridnew.view;

import java.io.Serializable;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.iiapk.gridnew.FlingGalleryActivity;
import com.iiapk.gridnew.R;
import com.iiapk.gridnew.WebViewPagerActivity;
import com.iiapk.gridnew.domain.Article;

public class UnitNews extends LinearLayout{
	
	private RemoteImageView icon;
	private Context mContext;
	private int index;
	
	public UnitNews(Context context,Article article,int index1){
		super(context, null);
		mContext=context;
		setClickable(true);
		this.index=index1;
		View view = View.inflate(context, R.layout.panel_unitnews, null);
		TextView title = (TextView)view.findViewById(R.id.uintnews_title);
		icon = (RemoteImageView)view.findViewById(R.id.uintnews_icon);
		title.setText(article.title);
		icon.setImageResource(R.drawable.loading_100);
		this.addView(view);
		this.setPadding(5, 5, 5, 5);
		view.setOnClickListener(new OnClickListener(){
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(mContext,WebViewPagerActivity.class);
				intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				if(mContext instanceof FlingGalleryActivity){
					FlingGalleryActivity activity = (FlingGalleryActivity)mContext;
					intent.putExtra("datasource", (Serializable)activity.getDataSource());
					intent.putExtra("index",index);
				}
				mContext.startActivity(intent);
				((Activity)mContext).overridePendingTransition(R.anim.zoom_enter,R.anim.hold);
			}
		});
		icon.loadImage(""+article.imgR);
	}
	
}
